Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.1K
Visualizações
No se puede mostrar la URL del blob en "pdf-viewer" => "ng2-pdf-viewer" en Angular 10

Tengo una API que devuelve el archivo cargado como blob. Cuando trato de vincular src con URL de blob, no muestra nada, sin embargo, cuando intento vincular URL directa, puede mostrar un archivo PDF. Aquí está mi código dado a continuación.
Mi código TS

 downloadFile(fileData: Fileuploader) { this.tempBlob= null; //Fetching Data File this.apiservice.getDownloadfile(fileData).subscribe( (retFileData: any) => { this.tempRetFileData = retFileData; this.tempBlob = new Blob([retFileData], { type: this.contentType }); }, (err: Error) => { }, () => { const blob: Blob = new Blob([this.tempBlob], { type: this.contentType }); const fileName: string ='ilvsna.pdf'; this.myBlobURL = URL.createObjectURL(blob); } ); }

HTML

 <pdf-viewer [src]="myBlobURL" [render-text]="true" [original-size]="false" style="width: 400px; height: 500px" ></pdf-viewer>

Nota: si configuro la URL de myBlobURL en 'https://vadimdez.github.io/ng2-pdf-viewer/assets/pdf-test.pdf', entonces puede mostrar

over 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

Prueba esto.

t

 pdfSrc: Uint8Array; downloadFile(fileData: Fileuploader) { this.tempBlob= null; //Fetching Data File this.apiservice.getDownloadfile(fileData).subscribe( (retFileData: any) => { this.tempRetFileData = retFileData; this.tempBlob = new Blob([retFileData], { type: this.contentType }); const fileReader = new FileReader(); fileReader.onload = () => { this.pdfSrc = new Uint8Array(fileReader.result as ArrayBuffer); }; fileReader.readAsArrayBuffer(this.tempBlob); }, (err: Error) => { } ); }

html

 <pdf-viewer [src]="pdfSrc" [render-text]="true" [original-size]="false" style="width: 400px; height: 500px" ></pdf-viewer>
over 4 years ago · Santiago Trujillo Relatório

0

Creo que tengo una solución para ti. Puedes usar ArrayBuffer . @NF Code es correcto, sin embargo, usted dijo que recibió un error en la línea => this.pdfSrc = new Uint8Array(fileReader.result);
Entonces, cambie la línea a => this.pdfSrc = new Uint8Array(fileReader.result as ArrayBuffer); .
Finalmente, su código ts debería verse como a continuación =>

 downloadFile(fileData: Fileuploader) { this.tempBlob= null; //Fetching Data File this.apiservice.getDownloadfile(fileData).subscribe( (retFileData: any) => { this.tempRetFileData = retFileData; this.tempBlob = new Blob([retFileData], { type: this.contentType }); const fileReader = new FileReader(); fileReader.onload = () => { this.pdfSrc = new Uint8Array(fileReader.result as ArrayBuffer); }; fileReader.readAsArrayBuffer(this.tempBlob); }, (err: Error) => { } ); }
over 4 years ago · Santiago Trujillo Relatório

0

Resuelvo con window.URL.createObjectURL de mi archivo de blob de devolución del servicio:
-- archivo ts

 this.obuService.getObuDocument(obuId, fileId).subscribe( (data: HttpResponse<Blob>) => { const url = window.URL.createObjectURL(data.body); this.src = url; this.viewPDF = true; } );

-- Servicio

 getObuDocument(obuId: number, fileId: number): Observable<any> { const options = { observe: 'response' as 'body', Accept: 'application/pdf', responseType: 'blob' as 'blob' }; return this.http.get(this.apiUrl + '/' + obuId + '/upload/' + fileId, options) .pipe(catchError(err => { throw err; }));

}

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda